package com.lqd.mall.system.controller;

import com.lqd.mall.basis.response.CommonResult;
import com.lqd.mall.basis.response.Result;
import com.lqd.mall.basis.utils.poi.ExcelUtil;
import com.lqd.mall.interaction.basis.vo.TableDataInfoVo;
import com.lqd.mall.interaction.system.SysOperLogEntity;
import com.lqd.mall.jpa.controller.BaseController;
import com.lqd.mall.log.annotation.Log;
import com.lqd.mall.log.enums.BusinessType;
import com.lqd.mall.security.annotation.InnerAuth;
import com.lqd.mall.system.SysOperLogControllerApi;
import com.lqd.mall.system.service.ISysOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @author 零起点
 * @create 2022-03-02 22:26
 */
@RestController
public class SysOperLogController extends BaseController implements SysOperLogControllerApi {

    @Autowired
    ISysOperLogService sysOperLogService;

    @Override
    @InnerAuth
    @Log(title = "保存操作日期内部",businessType = BusinessType.INSERT)
    public CommonResult save(SysOperLogEntity entity) {
        Integer save = sysOperLogService.save(entity);
        return CommonResult.SUCCESS();
    }

    @Override
    public Result<TableDataInfoVo<SysOperLogEntity>> list(SysOperLogEntity entity) {
        TableDataInfoVo<SysOperLogEntity> list = sysOperLogService.list(entity);
        return Result.SUCCESS(list);
    }

    @Override
    public CommonResult deleteSysOperaLog(Long operId) {
        return result(sysOperLogService.deleteSysOperaLog(operId));
    }

    @Override
    public CommonResult cleanSysOperaLog() {
        return result(sysOperLogService.delectEntity(new SysOperLogEntity()).get());
    }

    @Override
    public void exportSysOperaLog(HttpServletResponse response, SysOperLogEntity entity) {
        TableDataInfoVo<SysOperLogEntity> list = sysOperLogService.list(entity);
        ExcelUtil<SysOperLogEntity> excelUtil = new ExcelUtil<SysOperLogEntity>(SysOperLogEntity.class);
        excelUtil.exportExcel(response,list.getRows(),"操作日志");

    }
}
